//
//  RecordHeadView.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/3/11.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit

class RecordHeadView: UIView {
    lazy var headLabel1:UILabel = {
        let label = UILabel.init(frame: FRAME_CGFloat(SCREEN_WIDTH * 3 / 8 + 20, 46, 50, 15))
        label.font = Font_Semibold(11)
        label.textColor = RGB(230, 67, 64)
        return label
    }()
    lazy var headLabel2:UILabel = {
        let label = UILabel.init(frame: FRAME_CGFloat(SCREEN_WIDTH * 5 / 8 + 20, 46, 50, 15))
        label.font = Font_Semibold(11)
        label.textColor = RGB(230, 67, 64)
        return label
    }()
    
    var dateBlock:((_ num:Int) -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        let labelArr = ["历史","已购","缓存","书架"]
        self.addSubview(headLabel1)
        self.addSubview(headLabel2)
        
        for i in 0..<4 {
            let ind = (2 * CGFloat(i + 1) - 1) / 8
            let imageView = UIImageView(frame: CGRect(x:SCREEN_WIDTH * ind - 10.5, y:13.5, width:21, height:21))
            imageView.image = IMAGE(name: "record\(i)")
            self.addSubview(imageView)
            
            let label = UILabel.init(frame: FRAME_CGFloat(SCREEN_WIDTH * CGFloat(i) / 4, 41.5, SCREEN_WIDTH / 4, 24))
            label.font = FONT(17)
            label.textColor = RGB_Same(53)
            label.backgroundColor = .clear
            label.textAlignment = .center
            label.text = labelArr[i]
            self.addSubview(label)
            
            let btn = UIButton.init(type: .custom)
            btn.frame = FRAME_CGFloat(SCREEN_WIDTH * CGFloat(i) / 4, 0, SCREEN_WIDTH / 4, 74)
            btn.backgroundColor = UIColor.clear
            btn.addTarget(self, action: #selector(btnAction), for: .touchUpInside)
            btn.tag = 11 + i
            self.addSubview(btn)
        }
        
        let lineView = UIView.init(frame: FRAME_CGFloat(10, 74, SCREEN_WIDTH - 20, 1))
        lineView.backgroundColor = RGB_Same(240, 1)
        self.addSubview(lineView)
        
        
    }
    
    @objc func btnAction(btn:UIButton) {
        dateBlock?(btn.tag)
        switch btn.tag {
        case 11:
            print("11")
        case 12:
            print("12")
        case 13:
            print("13")
        case 14:
            print("14")
        default:
            return
        }
    }
    
}
